package com.kanshu.ksgb.fastread.doudou.module.ad

import java.util.*


/**
 * Title:
 * Description: 阅读器下方banner定时器
 * Copyright: Copyright(c)2018
 * Company: 看书网
 * CreateTime: 2018/11/15 11:21
 *
 * @author EvanHe
 * @version 3.0
 */
const val delayMs: Long = 1000 * 30

class AdTimerHelper(val processor: TimerProcessor?) {
    private var mTimer: Timer? = null
    private var mTimerTask: TimerTask? = null

    /**
     * 启动定时器
     */
    fun startTimer() {
        mTimer = Timer(true)
        mTimerTask = object : TimerTask() {
            override fun run() {
                processor?.process()
            }
        }
        mTimer?.schedule(mTimerTask, 0, delayMs)
    }

    /**
     * 停止定时器
     */
    fun stopTimer() {
        mTimer?.cancel()
        mTimerTask?.cancel()
        mTimer = null
        mTimerTask = null
    }

    interface TimerProcessor {
        fun process()
    }
}